package com.gigi.controller;

import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.gigi.entity.TypeShiqinEntity;
import com.gigi.model.IdRequest;
import com.gigi.model.ListRequest;
import com.gigi.model.TypeTagDO;
import com.gigi.service.manual.TypeManageService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 分类管理
 */
@RestController
@RequestMapping("type-manage")
public class TypeManageController {

    private final TypeManageService typeManageService;

    public TypeManageController(TypeManageService typeManageService) {
        this.typeManageService = typeManageService;
    }

    @ApiOperation(value = "列表")
    @PostMapping("/list")
    public MultiResponse<TypeShiqinEntity> list(@RequestBody ListRequest request) {
        return typeManageService.list(request);
    }

    @ApiOperation(value = "详情")
    @PostMapping("/detail")
    public SingleResponse<TypeShiqinEntity> detail(@RequestBody @Valid IdRequest request) {
        return typeManageService.detail(request.getId());
    }

    @ApiOperation(value = "保存")
    @PostMapping("/save")
    public Response save(@RequestBody @Valid TypeTagDO request) {
        return typeManageService.save(request);
    }

    @ApiOperation(value = "删除")
    @PostMapping("/delete")
    public Response delete(@RequestBody @Valid IdRequest request) {
        return typeManageService.delete(request.getId());
    }

}
